#ifndef GAME_H
#define GAME_H

#include <string>

#include "GameConf.h"
#include "../input/InputSystem.h"
#include "../control/menu/GUI.h"
#include "GameObject.h"
#include "Map.h"
#include "Unit.h"

// Provides quick look up of a unit given its id (UnitMap[13] returns a pointer to the unit with id 13)
typedef map <long, Unit*> UnitMap;

class Game : public InputInterface
{
	static Game* thisInstance;
	
	vector<GameObject*> selected;
	int mouseDownX, mouseDownY;
	GUI gui;
	Map map;
	UnitMap units;
	
	DebugRect selectionRect;
	
public:
	Game();
	~Game();
	
	void init(string game_config_file, const GameConf& game_conf);
	
	static inline Game* Instance() { return Game::thisInstance; }
	
	void onMouseButtonDown(KEY_TYPE, int, int);
	void onMouseButtonUp(KEY_TYPE, int, int);
	
	void onKeyDown(KEY_TYPE);
	void onKeyUp(KEY_TYPE);
	
	void onMouseWheelUp();
	void onMouseWheelDown();
	
	void onMouseMove(int, int);
	
	void onWindowResize(float W, float H);
	
	bool traceMousePos(int, int, lVec3D&);
	
	Map& getMap() { return map; }
	
	void step(unsigned dt);
	
	void pauseGame();
	void resumeGame();
	
	void select_point(const lVec3D& where);
	void select_range(const fVec2D& A, const fVec2D& B, const fVec2D &C, const fVec2D& D);
	
	void init_game(unsigned long seed);							// GAME_INIT
	void create_unit(char type[], unsigned x, unsigned y);		// UNIT_CREATE
	void move_unit(unsigned unit_id, unsigned x, unsigned y);	// UNIT_MOVE
};

#endif
